//
//  LJMListen_TableViewCell.m
//  wind
//
//  Created by 李金明 on 16/1/11.
//  Copyright © 2016年 李金明. All rights reserved.
//

#import "LJMListen_TableViewCell.h"
#import "LJMListenSub_TableViewCell.h"
#import "LJMListen_Model.h"
#define TOPHEIGHT 30//tableView的头视图的高度
#define TITLELEFT 10//标题距离左侧的距离
#define TITLEWIDTH 80//标题的宽度
#define TITLEHEIGTH 30//标题的高低
#define MOVEWIDTH 60//更多的宽度
#define MOVEURL @"http://api.favorite.ttpod.com/favorite/song/plaza?random=0&version=0&app=ttpod&v=v8.1.3.2015112716&user_id=0&mid=iPhone4S&f=f320&s=s310&imsi=&hid=&splus=7.0.4&active=1&net=2&openudid=1389d9dc18cb741587d90a5aead8646421f95dc0&idfa=C9BC818C-A0F5-4F04-8F8D-841910E08DF7&utdid=VmGiKEXHDQ0DAIL2FOnFFzxV&alf=201200&bundle_id=com.ttpod.music&latitude=&longtitude="
@interface LJMListen_TableViewCell () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UILabel *titleLab;
@property (nonatomic, retain) UILabel *titleSubLab;
@property (nonatomic, retain) UIButton *moreBut;
@property (nonatomic, retain) UITableView *tableV;
@end

@implementation LJMListen_TableViewCell
- (void)dealloc
{
    self.MOVEDelegatae = nil;
    self.cellDelegate = nil;
    [_titleSubLab release];
    [_titleLab release];
    [_moreBut release];
    [_tableV release];
    [super dealloc];
}
- (void)setDataArr:(NSMutableArray *)dataArr
{
    if (_dataArr != dataArr) {
        [_dataArr release];
        _dataArr = [dataArr retain];
        
    }
    [self.tableV reloadData];
    

}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatView];
    }
    return self;
}
- (void)creatView
{
    self.backgroundColor = [UIColor whiteColor];
    
    //添加tableView
    [self addTableView];
}
#pragma 添加tableView
- (void)addTableView
{
    self.tableV = [[UITableView alloc] init];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    //进制tableView的滑动
    self.tableV.scrollEnabled = NO;
    self.tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.contentView addSubview:self.tableV];
    
    [_tableV release];


}
#pragma layoutSubviews
- (void)layoutSubviews
{
    self.tableV.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    

}
#pragma tableView的协议方法
#pragma 数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
#pragma 高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
#pragma cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *str = @"cell";
    LJMListenSub_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (nil == cell) {
        cell = [[LJMListenSub_TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.numLab.text = [NSString stringWithFormat:@"%ld", indexPath.row];
    if (0 != self.dataArr.count) {
        LJMListen_Model *model = [self.dataArr objectAtIndex:indexPath.row];

        [cell.titleImageV sd_setImageWithURL:[NSURL URLWithString:model.picUrl] placeholderImage:nil];
        cell.titleLab.text = model.name;
        cell.sonerLab.text = model.singerName;
        cell.sonerStr = model.singerName;

    }

    
    return cell;
    
    
}
#pragma 组的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
#pragma 头视图的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return TOPHEIGHT;
}
#pragma 自定义头视图的方法
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, TOPHEIGHT)];
    headView.backgroundColor = [UIColor clearColor];
    
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.backgroundColor = [UIColor clearColor];
    self.titleLab.frame = CGRectMake(TITLELEFT, 0, TITLEWIDTH, TITLEHEIGTH);
    self.titleLab.text = @"大家在听";
    [headView addSubview:self.titleLab];
    [_titleLab release];
    
    self.titleSubLab = [[UILabel alloc] init];
    self.titleSubLab.backgroundColor = [UIColor clearColor];
    self.titleSubLab.text = @"(每小时更新)";
    self.titleSubLab.frame = CGRectMake(self.titleLab.frame.size.width + self.titleLab.frame.origin.x, self.titleLab.frame.origin.y, TITLEWIDTH, self.titleLab.frame.size.height);
    self.titleSubLab.font = [UIFont systemFontOfSize:13];
    self.titleSubLab.textColor = [UIColor grayColor];
    
    self.moreBut = [UIButton buttonWithType:UIButtonTypeCustom];
    self.moreBut.backgroundColor = [UIColor clearColor];
    [self.moreBut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.moreBut setTitle:@"更多" forState:UIControlStateNormal];
    self.moreBut.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.moreBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.moreBut.frame = CGRectMake(self.frame.size.width - MOVEWIDTH, self.titleLab.bounds.origin.y, MOVEWIDTH, TITLEHEIGTH);
    [headView addSubview:self.moreBut];

    [headView addSubview:self.titleSubLab];
    [_titleSubLab release];
    
    
    
    return headView;

}
#pragma 按键的方法
- (void)buttonAction:(UIButton *)sender
{
    if (sender == self.moreBut) {
        NSString *str = MOVEURL;
        [self.MOVEDelegatae changeMoveVCUrl:str];
    }
}
#pragma 按键的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.cellDelegate changeMoveVCInt:indexPath.row];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
